package com.dunqi.gpm.cangxi.WeekReport.WeekReport.WeekReportDetail;

import android.annotation.SuppressLint;

import com.dunqi.gpm.cangxi.WeekReport.Model.Projects;
import com.dunqi.gpm.cangxi.WeekReport.Model.WeeklyPlanBean;
import com.dunqi.gpm.cangxi.common.api.ApiFactory;
import com.dunqi.gpm.cangxi.common.api.RxSchedulers;
import com.dunqi.gpm.cangxi.common.base.Data;
import com.dunqi.gpm.cangxi.common.util.CommonUtil;
import com.dunqi.gpm.cangxi.home.bean.Page;

import java.util.HashMap;

import okhttp3.RequestBody;

public class WeekReportDetailModel {
    interface WeekReportResult {

        void fail(Throwable throwable);

        void delete(Data data);

        void projectName(Page<Projects> projects);

        void plans(Page<WeeklyPlanBean> plans);

        void save(Data save);
    }

    @SuppressLint("CheckResult")
    public void delete(Integer id, WeekReportResult result) {
        ApiFactory.getInstance()
                .projectWeekPlandelete(CommonUtil.getDeviceId(), id)
                .compose(RxSchedulers.io_main())
                .subscribe(result::delete, result::fail);
    }

    /**
     * 获取企业列表
     *
     * @param result
     */
    @SuppressLint("CheckResult")
    public void getProjectName(WeekReportResult result) {
        ApiFactory.getInstance()
                .projectWeeklyReportProjectName(CommonUtil.getDeviceId())
                .compose(RxSchedulers.io_main())
                .subscribe(result::projectName, result::fail);
    }

    /**
     * 新增周报 - 获取项目计划信息
     *
     * @param projectId
     */
    @SuppressLint("CheckResult")
    public void projectWeeklyReportgetWeeksInfos(WeekReportResult result, int projectId) {
        ApiFactory.getInstance()
                .projectWeeklyReportgetWeeksInfos(CommonUtil.getDeviceId(), projectId)
                .compose(RxSchedulers.io_main())
                .subscribe(result::plans, result::fail);
    }

    /**
     * 周报告 保存 或 提交
     *
     * @param
     */
    @SuppressLint("CheckResult")
    public void save(WeekReportResult result, HashMap<String, RequestBody> files) {
        ApiFactory.getInstance()
                .projectWeekReportSave(files)
                .compose(RxSchedulers.io_main())
                .subscribe(result::save, result::fail);
    }
}
